# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=importlib_resources
pkgbase=mingw-w64-python2-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}")
pkgver=1.0.2
pkgrel=1
pkgdesc="Read resources from Python packages (mingw-w64)"
arch=('any')
url='https://pypi.python.org/pypi/importlib_resources'
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python2"
         "${MINGW_PACKAGE_PREFIX}-python2-typing"
         "${MINGW_PACKAGE_PREFIX}-python2-pathlib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/i/importlib_resources/importlib_resources-$pkgver.tar.gz")
sha256sums=('d3279fd0f6f847cced9f7acc19bd3e5df54d34f93a2e7bb5f238f81545787078')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"
  rm -rf ${builddir} | true
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
    msg "Python 2 build for ${CARCH}"  
    cd "${srcdir}/python2-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python2 setup.py build
}

check() {
    msg "Python 2 test for ${CARCH}"
    cd "${srcdir}/python2-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python2 -m unittest discover
}


package() {
  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}
